from google.appengine.ext import db
from google.appengine.ext.db.polymodel import PolyModel
from google.appengine.ext.db import djangoforms
from google.appengine.dist import use_library
use_library('django','0.96')

class Experiment(db.Model):
  coordinator = db.UserProperty()
  name = db.StringProperty()
  collaborators = db.ListProperty(db.Key)
  watchers = db.ListProperty(db.Key)
  hypothesis = db.TextProperty()
  stage = db.IntegerProperty()
  spreadsheet = db.StringProperty()

class CreateExperimentForm(djangoforms.ModelForm):
  class Meta:
    model = Experiment
    fields = ['name']

class EditHypothesisForm(djangoforms.ModelForm):
  class Meta:
    model = Experiment
    fields = ['hypothesis']
    #widgets = {'hypothesis': forms.Textarea(attrs={'class':'markItUp'})}

class Scenario(db.Model):
  experiment = db.ReferenceProperty(Experiment)
  variables = db.StringListProperty()

class AddVariableForm(djangoforms.ModelForm):
  class Meta:
    model = Scenario
    fields = ['variables']

class Step(PolyModel):
  scenario = db.ReferenceProperty(Scenario)
  description = db.TextProperty()
  repeat = db.IntegerProperty()
  timeout = db.IntegerProperty()
  variables = db.StringListProperty()
  children = db.ListProperty(db.Key)
  next = db.SelfReferenceProperty()

class AddStepForm(djangoforms.ModelForm):
  class Meta:
    model = Step
    fields = ['description', 'repeat', 'timeout']
